package com.ruoyi.system.basicInformation.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.Page;
import com.ruoyi.system.basicInformation.bo.TElectronicFenceObjectAddBo;
import com.ruoyi.system.basicInformation.bo.TElectronicFenceObjectQueryBo;
import com.ruoyi.system.basicInformation.bo.TElectronicFenceObjectEditBo;
import com.ruoyi.system.basicInformation.domain.TElectronicFenceObject;
import com.ruoyi.system.basicInformation.mapper.TElectronicFenceObjectMapper;
import com.ruoyi.system.basicInformation.vo.TElectronicFenceObjectVo;
import com.ruoyi.system.basicInformation.service.ITElectronicFenceObjectService;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 电子围栏关联对象Service业务层处理
 *
 * @author ruoyi
 * @date 2021-05-20
 */
@Service
public class TElectronicFenceObjectServiceImpl extends ServiceImpl<TElectronicFenceObjectMapper, TElectronicFenceObject> implements ITElectronicFenceObjectService {

    @Autowired
    TElectronicFenceObjectMapper tElectronicFenceObjectMapper;
    @Override
    public TElectronicFenceObjectVo queryById(Long id){
        TElectronicFenceObject db = this.baseMapper.selectById(id);
        return BeanUtil.toBean(db, TElectronicFenceObjectVo.class);
    }

    @Override
    public List<TElectronicFenceObjectVo> queryList(TElectronicFenceObjectQueryBo bo) {
        return  tElectronicFenceObjectMapper.queryListForName(bo);
    }


    @Override
    public Boolean insertByAddBo(TElectronicFenceObjectAddBo bo) {
        TElectronicFenceObject add = BeanUtil.toBean(bo, TElectronicFenceObject.class);
        validEntityBeforeSave(add);
        return this.save(add);
    }

    @Override
    public Boolean updateByEditBo(TElectronicFenceObjectEditBo bo) {
        TElectronicFenceObject update = BeanUtil.toBean(bo, TElectronicFenceObject.class);
        validEntityBeforeSave(update);
        return this.updateById(update);
    }

    /**
     * 保存前的数据校验
     *
     * @param entity 实体类数据
     */
    private void validEntityBeforeSave(TElectronicFenceObject entity){
        //TODO 做一些数据校验,如唯一约束
    }

    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return this.removeByIds(ids);
    }
}
